package com.ldk.springboot2021.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ldk.springboot2021.mapper.Order_DoorMapper;
import com.ldk.springboot2021.pojo.Door;
import com.ldk.springboot2021.pojo.Order_Door;
import com.ldk.springboot2021.service.DoorService;
import com.ldk.springboot2021.service.Order_DoorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service//这个类加了这个注解，才能被Spring管理
public class Order_DoorServiceImpl implements Order_DoorService {
    //注入持久层对象

@Autowired(required = false)
private Order_DoorMapper order_doorMapper;


    @Override
    public String addOrderInfo(Order_Door order_door, Model model) {
        order_door
                .setDoorId(order_door.getDoorId())
                .setOrderNo(order_door.getOrderNo())
                .setOrderType(order_door.getOrderType())
                .setPersonNum(order_door.getPersonNum())
                .setCashier(order_door.getCashier())
                .setCreateTime(new Date())
                .setEndTime(new Date())
                .setPaymentType(order_door.getPaymentType())
                .setPrice(order_door.getPrice())
                .setCreated(new Date());
        order_doorMapper.insert(order_door);
        model.addAttribute("order",order_door);
        return "redirect:/order/findAllOrders";
    }

    @Override
    public String findAllOrdersInfo(Model model) {
        QueryWrapper<Order_Door> queryWrapper=new QueryWrapper<>();
        List<Order_Door> list = order_doorMapper.selectList(queryWrapper);
        System.out.println(list);
        model.addAttribute("orderList",list);
        return "orderList";
    }

    @Override
    public String deleteByOrderId(Integer doorId) {
        order_doorMapper.deleteById(doorId);
        return "redirect:/order/findAllOrders";
    }
}
